package leetcode_core.leetcode_1;

import org.junit.jupiter.api.Test;

import java.util.HashMap;
import java.util.Map;
import java.util.Stack;

public class NextGreaterElement1 {

    public int[] nextGreaterElement(int[] nums1, int[] nums2) {
        int[] ans = new int[nums1.length];
        Stack<Integer> s = new Stack<>();
        Map m = new HashMap<Integer,Integer>();
        for(int i = nums2.length-1;i>=0;i--){
            while(!s.empty() && nums2[i] >= s.peek()){
                s.pop();
            }
            m.put(nums2[i],s.isEmpty()?-1:s.peek());
            s.push(nums2[i]);
        }
        for(int i = 0;i<nums1.length;i++){
            ans[i] = (int)m.get(nums1[i]);
        }
        return ans;
    }

    @Test
    public void test(){
        System.out.println();
    }

}
